/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2018
 */

package com.bm.console.business.impl;

import com.sys.console.cookie.Constant_Cookie;
import com.sys.console.pojo.Sys_User;
import com.sys.object.common.page.PageBean;

import com.bm.console.business.WebHelpFindHouseService;
import com.bm.console.pojo.WebHelpFindHouse;
import com.bm.console.pojo.mapper.WebHelpFindHouseMapper;

import java.util.Date;
import java.util.List;

import org.apache.http.protocol.HTTP;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sys.object.common.page.PageBean;

import javax.servlet.http.HttpServletRequest;

@Service
public class WebHelpFindHouseServiceImpl implements WebHelpFindHouseService {

    @Autowired
    WebHelpFindHouseMapper webHelpFindHouseMapper;

    @Autowired
    private HttpServletRequest request;

    @Override
    public PageBean queryPageList(WebHelpFindHouse entity, PageBean page) throws Exception {
        int rowCount = webHelpFindHouseMapper.selectByPageCount(entity);
        page.setRowCount(rowCount);
        entity.setOffset(page.getStartRow());
        entity.setLimit(page.getPerpage());
        page.setList(webHelpFindHouseMapper.selectByPage(entity));
        return page;
    }

    public WebHelpFindHouse queryByPrimaryKey(Integer id) throws Exception {
        return webHelpFindHouseMapper.selectByPrimaryKey(id);
    }

    public int saveOrUpdate(WebHelpFindHouse entity) throws Exception {
        Sys_User currentUser = (Sys_User) request.getSession().getAttribute(Constant_Cookie.CURRENT_USER_SESSION);
        if (entity.getId() != null && entity.getId() > 0) {
            entity.setUpdateTime(new Date());
            entity.setUpdateId(Long.valueOf(currentUser.getUid()));
            if (entity.getIsView()) {
                entity.setViewTime(new Date());
            }
            return this.webHelpFindHouseMapper.updateByPrimaryKeySelective(entity);
        }
        entity.setCreateId(Long.valueOf(currentUser.getUid()));
        entity.setCreateId(Long.valueOf(currentUser.getUid()));
        return this.webHelpFindHouseMapper.insert(entity);
    }

    public int remove(Integer id) throws Exception {
        return this.webHelpFindHouseMapper.deleteByPrimaryKey(id);
    }

    public int delete(Integer id) throws Exception {
        return this.webHelpFindHouseMapper.deleteByPrimaryKey(id);
    }

    public int updateStatus(WebHelpFindHouse entity) throws Exception {
        return this.webHelpFindHouseMapper.updateByPrimaryKeySelective(entity);
    }

    public int updateStatus(String status, String[] ids)
            throws Exception {
        return 0;
    }


}
